﻿namespace RotovapPlatform.Domain.Equipment.Interfaces.Base;

using RotovapPlatform.Domain.Equipment.Device.Motors.Dto;
using RotovapPlatform.Domain.Equipment.DeviceParameters;
using System.Threading.Tasks;

/// <summary>
/// 电机设备基础接口
/// </summary>
public interface IMotorBase : IEquipmentBase
{
	/// <summary>
	/// 轴号
	/// </summary>
	short AxisNo { get; }

	/// <summary>
	/// 使能
	/// </summary>
	Task<bool> EnableAsync();

	/// <summary>
	/// 去使能
	/// </summary>
	Task<bool> DisableAsync();

	/// <summary>
	/// 执行回零操作
	/// </summary>
	Task<bool> HomeAsync();

	/// <summary>
	/// 执行Jog+操作
	/// </summary>
	/// <param name="jogSpeed">Jog速度(rpm)</param>
	Task<bool> JogPlusAsync(double jogSpeed);

	/// <summary>
	/// 执行Jog-操作
	/// </summary>
	/// <param name="jogSpeed">Jog速度(rpm)</param>
	Task<bool> JogMinusAsync(double jogSpeed);

	/// <summary>
	/// 执行绝对定位（带参数）
	/// </summary>
	/// <param name="position">目标位置（用户单位）</param>
	/// <param name="speed">运行速度</param>
	/// <param name="acceleration">加速度</param>
	/// <param name="deceleration">减速度</param>
	Task<bool> AbsoluteMoveAsync(double position, double speed, double acceleration, double deceleration);

	/// <summary>
	/// 执行相对定位
	/// </summary>
	Task<bool> RelativeMoveAsync();

	/// <summary>
	/// 执行速度运行
	/// </summary>
	Task<bool> SpeedRunAsync();

	/// <summary>
	/// 执行停止
	/// </summary>
	Task<bool> StopJogAsync();

	/// <summary>
	/// 获取电机状态
	/// </summary>
	Task<MotorStatus> GetStatusAsync();

	/// <summary>
	/// 设置电机参数
	/// </summary>
	/// <param name="parameters">电机参数</param>
	void SetMotorParameters(MotorParameters parameters);

	/// <summary>
	/// 获取电机参数
	/// </summary>
	/// <returns>电机参数</returns>
	MotorParameters GetMotorParameters();

	/// <summary>
	/// 设置电机运动参数
	/// </summary>
	/// <param name="position">目标位置</param>
	/// <param name="speed">速度</param>
	/// <param name="acceleration">加速度</param>
	/// <param name="deceleration">减速度</param>
	/// <returns>是否成功</returns>
	Task<bool> SetMotionParametersAsync(double position, double speed, double acceleration, double deceleration);

	/// <summary>
	/// 设置扭矩模式下的最大限速
	/// </summary>
	/// <param name="maxSpeed">最大速度（脉冲/秒）</param>
	/// <returns>是否成功</returns>
	Task<bool> SetMaxSpeedAsync(uint maxSpeed);

	/// <summary>
	/// 设置电机运行模式
	/// </summary>
	/// <param name="targetMode">目标模式（10:扭矩模式，8:位置模式）</param>
	/// <returns>是否成功</returns>
	Task<bool> SetModeAsync(short targetMode);

	/// <summary>
	/// 设置转矩和转矩变化率
	/// </summary>
	/// <param name="targetTorque">目标转矩（千分比）</param>
	/// <param name="torqueChangeRate">转矩变化率</param>
	/// <returns>是否成功</returns>
	Task<bool> SetTorqueAsync(short targetTorque, double torqueChangeRate);

	/// <summary>
	/// 读取当前转矩
	/// </summary>
	/// <returns>当前转矩值</returns>
	Task<short> GetCurrentTorqueAsync();

	/// <summary>
	/// 复位轴
	/// </summary>
	/// <returns>操作是否成功</returns>
	Task<bool> ResetAxisAsync();
}